const fileTypeMap = ['docx', 'pdf', 'xlsx', 'image', 'video']

/**
 *
 * @param extension 文件后缀
 * @returns 文件类型
 */
export function findType(extension) {
  const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp']
  const videoExtensions = ['mp4', 'avi', 'mov', 'wmv', 'flv', 'qt']
  let fileType = extension
  if (imageExtensions.includes(fileType)) {
    fileType = 'image'
  } else if (videoExtensions.includes(fileType)) {
    fileType = 'video'
  }
  return fileType
}
/**
 *
 * @param Url 文件路径
 * @returns
 */
export function getFileExtensionByUrl(Url) {
  return Url?.split('.')?.pop()?.toLowerCase()
}
/**
 *
 * @param element 需要全屏的元素
 */
export function requestFullScreen(element) {
  if (!element) return
  if (element.requestFullscreen) {
    element.requestFullscreen()
  } else if (element.mozRequestFullScreen) {
    // Firefox
    element.mozRequestFullScreen()
  } else if (element.webkitRequestFullscreen) {
    // Chrome, Safari and Opera
    element.webkitRequestFullscreen()
  } else if (element.msRequestFullscreen) {
    // IE/Edge
    element.msRequestFullscreen()
  }
}

/**
 * 判断文件是否可预览
 * @param src  文件路径
 * @returns
 */
export const getFileCanView: any = (src) => {
  const extension = getFileExtensionByUrl(src)
  return fileTypeMap.includes(findType(extension))
}
